package org.wkg.lesson05;

import java.util.concurrent.TimeUnit;

public class Demo_501 {

    public static void main(String[] args) {
        Object lock = new Object();

        Thread t1 = new Thread(() -> {
               while (true){
                   System.out.println("wait之前....");
                   synchronized (lock){
                       try {
                           lock.wait();
                       } catch (InterruptedException e) {
                           throw new RuntimeException(e);
                       }
                   }
                   System.out.println("wait之后....");
                   System.out.println("===================");

               }
        });



        Thread t2 = new Thread(() -> {
            while (true) {
                System.out.println("notify之前....");
                synchronized (lock){
                    lock.notify();
                }
                System.out.println("notify之后....");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });

        t1.start();
        t2.start();
    }
}
